package land_register;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DB.DB_connection_pool;

public class Phone_register_tf extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		
		String phone = request.getParameter("phone");
		String phone_select = "select user_telephone from land_table where user_telephone='"+phone+"'";
		
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps= conn.prepareStatement(phone_select);
			ResultSet rs =  ps.executeQuery();
			if(rs.next()){      //查询出电话已被注册
				out.print("0");
			}
			else{         //未被注册
				out.print("1");
			}
			
			ps.close();
			rs.close();
			out.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
